/*
 * SPDX-License-Identifier: Apache-2.0
 * Copyright Blazebit
 */

package com.blazebit.persistence.testsuite.entity;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

/**
 *
 * @author Christian Beikov
 * @since 1.1.0
 */
@Entity
public class RecursiveEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    private Long id;
    private String name;
    private RecursiveEntity parent;
    private Set<RecursiveEntity> children = new HashSet<>(0);
    private Set<RecursiveEntity> children2 = new HashSet<>(0);

    public RecursiveEntity() {
    }

    public RecursiveEntity(String name) {
        this.name = name;
    }

    public RecursiveEntity(String name, RecursiveEntity parent) {
        this.name = name;
        this.parent = parent;
    }

    @Id
    @GeneratedValue
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Basic(optional = false)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    public RecursiveEntity getParent() {
        return parent;
    }

    public void setParent(RecursiveEntity parent) {
        this.parent = parent;
    }

    @OneToMany(mappedBy = "parent")
    public Set<RecursiveEntity> getChildren() {
        return children;
    }

    public void setChildren(Set<RecursiveEntity> children) {
        this.children = children;
    }

    @OneToMany
    @JoinTable(name = "recursive_children2")
    public Set<RecursiveEntity> getChildren2() {
        return children2;
    }

    public void setChildren2(Set<RecursiveEntity> children2) {
        this.children2 = children2;
    }
}
